package com.tbs.parkingsaleapp.UI.Adapters;

import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;
import com.tbs.parkingsaleapp.Http.JsonData.DiscountInfo;
import com.tbs.parkingsaleapp.R;

import java.util.ArrayList;

public class DiscountAdapter extends BaseAdapter {

    DiscountInfo[] infos;
    ListView ls;
    public DiscountAdapter(DiscountInfo[] infos,ListView ls)
    {
        this.ls=ls;
        this.infos=infos;
        for (DiscountInfo v:infos
             ) {
            shows.add(v);
        }
    }
    ArrayList<DiscountInfo> shows=new ArrayList<>();

    @Override
    public int getCount() {
        return shows.size();
    }

    @Override
    public Object getItem(int position) {
        return shows.get(position);
    }

    @Override
    public long getItemId(int position) {
        return shows.get(position).getOrderID();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        if(convertView!=null)
            return convertView;
        DiscountInfo info=shows.get(position);
        View root= View.inflate(parent.getContext(), R.layout.singlediscount_layout,null);
        root.setTag(false);
        TextView textView= root.findViewById(R.id.discount_content);
        textView.setText(String.format("%s\n单独使用后的订单价格:%.2f\n领取时间:%s",info.getContent(),info.getAfterPrice(),info.getDiscount().getPickTime()));
        return root;
    }
}
